package day07;

import java.util.Scanner;

/*
需求：
  机票价格按照淡季旺季、头等舱、商务舱和经济舱收费，
  输入机票原价、月份和头等舱、商务舱或经济舱，
  其中旺季（5-10月）头等舱9折，商务舱85折，经济舱8折，
  淡季（11月到来年4月）头等舱7折，商务舱65折，经济舱6折，
  最终输出机票价格
 */
public class CalAirPrice {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入机票票价");
        double price = sc.nextDouble();
        System.out.println("请输入月份");
        int month = sc.nextInt();
        System.out.println("请输入舱位: 1.头等舱 2.商务舱 3.经济舱");
        int type = sc.nextInt();
        double finalPrice = calAirPrice(price, month, type);
        if (finalPrice > 0) {
            System.out.println("机票的最终价格为:" + finalPrice);
        }

    }

    public static double calAirPrice(double price, int month, int type) {
        double finalPrice = 0.0;
        if (price < 0) {
            System.out.println("票价输入有误,请重新输入");
            return price;
        }
        if (month <= 0 || month > 12) {
            System.out.println("月份输入有误,请重新输入");
            return -1;
        }
        if (type < 1 || type > 3) {
            System.out.println("舱位输入有误,请重新输入");
            return -1;
        }
        if (month >= 5 && month <= 10) {
            finalPrice = countPrice(price, type, 0.9, 0.85, 0.8);
        } else {
            finalPrice = countPrice(price, type, 0.7, 0.65, 0.6);
        }
        return finalPrice;
    }

    public static double countPrice(double price, int type, double discount1, double discount2, double discount3) {
        if (type == 1) {
            price *= discount1;
        } else if (type == 2) {
            price *= discount2;
        } else {
            price *= discount3;
        }
        return price;
    }
}
